/**
 * @作者:黎谢之
 * @创建时间：2021/7/7
 * @修改时间：2021/7/10
 */
package com.example.senior_bug.controller;

import com.example.senior_bug.EntityClass.Customer;
import com.example.senior_bug.ToolClass.Result;

import com.example.senior_bug.Service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
@CrossOrigin
@RequestMapping("/Customer")
public class CustomerController {
    @Autowired
    private CustomerService customerService;

    //测试
    @RequestMapping("/All")
    public Result GetAll() {
        return customerService.getAll();
    }

    //获取购物车
    @RequestMapping("/MyShoppingCart")
    public Result GetAllSkuByCustomerName(@RequestParam String CustomerName) {
        return customerService.GetAllSkuByCustomerName(CustomerName);
    }

    //添加购物车
    @RequestMapping("/addShoppingCart")
    public Result AddShoppingCart(@RequestParam int skuID, @RequestParam int index, @RequestParam String Name) {
        return customerService.PutSkuInShoppingCart(skuID, index, Name);
    }

    //删除购物车
    @RequestMapping("/deleteShoppingCart")
    public Result DeleteShoppingCart(@RequestParam int ConcreteSKUId, String Name) {
        return customerService.DeleteSkuInShoppingCart(ConcreteSKUId, Name);
    }

    //通过电话号码登录
    @RequestMapping("/LoginByPhone")
    public Result LoginByPhoneNum(@RequestParam String PhoneNum, @RequestParam String Password) {
        return customerService.LoginByPhone(PhoneNum, Password);
    }

    //通过邮箱登录
    @RequestMapping("/LoginByEmail")
    public Result LoginByEmail(@RequestParam String Email, @RequestParam String Password) {
        return customerService.LoginByEmail(Email, Password);
    }

    //获取主键
    @RequestMapping("/getIdByCustomerName")
    public Result GetIdByCustomerName(@RequestParam String CustomerName) {
        return customerService.getIdByCustomerName(CustomerName);
    }

    //修改个人信息
    @RequestMapping(value = "/ModifyTheInfo", method = RequestMethod.POST, produces = "application/json")
    public Result ModifyTheInfo(@RequestParam("face") MultipartFile file, @RequestParam int id,
                                @RequestParam String name, @RequestParam String phoneNum, @RequestParam String email) {
        return customerService.ModifyTheInfo(file, id, name, phoneNum, email);
    }

    //个人主页查询
    @RequestMapping("/getCustomerById")
    public Result GetCustomerById(@RequestParam int Id) {
        return customerService.getById(Id);
    }

    //用户注册同传头像
    @RequestMapping(value = "/RegisterWithFaceImage", method = RequestMethod.POST, produces = "application/json")
    public Result RegisterWithFaceImage(@RequestParam("face") MultipartFile file, String name,
                                        String passWord, String phoneNum,
                                        String email) {

        Customer customer = new Customer();
        customer.setName(name);
        customer.setPassWord(passWord);
        if (phoneNum != null)
            customer.setPhoneNum(phoneNum);
        if (email != null)
            customer.setEmail(email);
        return customerService.RegisterWithFaceImage(file, customer);
    }

    //用户获取所有聊天的商家
    @RequestMapping("/getAllBusiness")
    public Result GetAllCustomer(@RequestParam int CustomerId) {
        return customerService.getAllBusiness(CustomerId);
    }

    //用户添加新的聊天商家
    @RequestMapping("/AddNewBusiness")
    public Result CommunicateWithNewBusiness(int CustomerId, int BusinessId) {
        return customerService.CommunicateWithNewBusiness(CustomerId, BusinessId);
    }

    //用户在商品首页显示各种订单的数量
    @RequestMapping("/NumOfOrder")
    public Result NumOfOrder(@RequestParam int CustomerId) {
        return customerService.NumOfOrder(CustomerId);
    }

    //用户获取推荐列表
    @RequestMapping("/Recommend")
    public Result GetAllRecommendSKU(@RequestParam int CustomerId) {
        return customerService.getRecommendSku(CustomerId);
    }
}

